﻿using ClieOp.Record;
using NUnit.Framework;

namespace ClieOpTest
{
    [TestFixture]
    internal class FieldTest
    {
        [Test, ExpectedException(ExpectedMessage = "Cannot set value on read-only field.")]
        public void AttemptToSetReadOnlyValue()
        {
            var field = new Field(FieldName.Recordcode, FieldType.TypeX, 5, "XXXXX");
            field.Value = "YYYYY";
            Assert.AreEqual("XXXXX", field.Value);
        }

        [Test]
        public void EqualsTest()
        {
            var field1 = new Field(FieldName.Recordcode, FieldType.TypeX, 5, "XXXXX");
            var field2 = new Field(FieldName.Recordcode, FieldType.TypeX, 5, "XXXXX");
            var field3 = new Field(FieldName.Filler, FieldType.TypeX, 5, "XXXXX");
            Assert.IsTrue(field1 == "XXXXX");
            Assert.IsFalse(field1 == "YYYYY");
            Assert.IsFalse(field1 != "XXXXX");
            Assert.IsTrue(field1 != "YYYYY");
            Assert.IsTrue(field1 == field2);
            Assert.IsFalse(field1 == field3);
            Assert.IsTrue(field1.Equals((object)field2));
            Assert.IsTrue(field1.Equals(field1));
            Assert.IsFalse((Field)null == null);
        }

        [Test]
        public void ReadOnlyTest()
        {
            var field = new Field(FieldName.Recordcode, FieldType.TypeX, 5, "XXXXX");
            Assert.IsTrue(field.IsReadOnly);
            field = new Field(FieldName.Recordcode, FieldType.TypeX, 5);
            Assert.IsFalse(field.IsReadOnly);
            field = new Field(FieldName.Vasteomschrijving, FieldType.TypeX, 32);
            Assert.IsFalse(field.IsReadOnly);
        }
    }
}